knitr::opts_chunk$set(echo = TRUE)

# Load libraries for homework problems
library(tidyverse)
library(gt)

# Read in the data
abpm_wide <- read_csv('data/abpm_wide_synthetic.csv')

Overview

Ambulatory blood pressure monitoring (ABPM) is a technique for assessing a person’s blood pressure (BP). ABPM is conducted with a special device that consists of a BP cuff worn on the participant’s arm and attached to a small recording device worn on the belt. The ABPM device is usually worn for 24 hours, and it records BP periodically (usually at 15-minute or 30-minute intervals). One of the benefits of ABPM is measuring BP during routine daily activities and during sleep instead of in clinical settings. A previous study by Hermida et al. (2018) found that, among all BP derive risk factors, asleep Systolic BP is the most associated with cardiovacular disease events.

Data dictionary

I have modified the New York times data to include information about state’s population levels. The data are described below:

c("sleep_time" = "Time of falling asleep", 
  "awake_time" =  "Time of waking up", 
  "age" = "Participant age, years",
  "sex" = "Participant sex at birth",
  "race" = "Participant race",
  "educ" = "Participant education at exam time",
  "smoke" = "Participant smoking status at exam time",
  "sbp_0 - sbp_23" = "Systolic BP, hours since midnight",
  "dbp_0 - dbp_23" = "Diastolic BP, hours since midnight",
  "hr_0 - hr_23" = "Heart rate, hours since midnight"
) %>% 
  enframe() %>% 
  gt(rowname_col = "name") %>%
  tab_stubhead(label = 'Variable name') %>% 
  cols_label(value = 'Variable description') %>% 
  cols_align('right') %>%
  tab_source_note("BP = blood pressure") %>% 
  tab_header(title = 'Dictionary for synthetic ABPM data')
Dictionary for synthetic ABPM data
Variable name Variable description
sleep_time Time of falling asleep
awake_time Time of waking up
age Participant age, years
sex Participant sex at birth
race Participant race
educ Participant education at exam time
smoke Participant smoking status at exam time
sbp_0 - sbp_23 Systolic BP, hours since midnight
dbp_0 - dbp_23 Diastolic BP, hours since midnight
hr_0 - hr_23 Heart rate, hours since midnight
BP = blood pressure

Data

The data (cv19) are printed below:

abpm_wide

Problem 1

Convert the smoke variable in abpm_wide into a factor and exclude participants with missing data for sleep_time, awake_time, and smoke.

Notes:

The factor labels should be

  • Never smoked
  • Former smoker
  • Current smoker
read_rds('solutions/01_solution.rds')

Problem 2

Pivot the data into a longer format.

Notes:

  • Create a column named id that uniquely identifies each row of abpm_wide.

  • Pivot the data into a longer form such that each id has a column for sbp, dbp, and hr. You may need to use pivot_longer, then separate, then pivot_wider.

  • Drop all rows with missing data for sbp, dbp, or hr

read_rds('solutions/02_solution.rds')

Problem 3

Create an factor variable called awake that has values of 'Yes' when participants are awake and 'No' when asleep.

Notes:

  • There are two scenarios that are relevant:

    • sleep time is less than awake time

    • sleep time is greater than awake time.

read_rds('solutions/03_solution.rds')

Problem 4

Notes:

read_rds('solutions/04_solution.rds')

Problem 5

Notes:

read_rds('solutions/05_solution.rds')

Hermida, Ramon C, Juan J Crespo, Alfonso Otero, Manuel Dominguez-Sardina, Ana Moya, Maria T Rios, Maria C Castineira, et al. 2018. “Asleep Blood Pressure: Significant Prognostic Marker of Vascular Risk and Therapeutic Target for Prevention.” European Heart Journal 39 (47): 4159–71.